package com.lanou.controller;

import com.lanou.entity.ConsultantEvaluation;
import com.lanou.service.ConsultantEvaluationService;
import com.lanou.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName ConsultantEvaluationController
 * @Description TODO
 * @Author chenzhaobao
 * @Date 2025年08月15日 10:03
 * @Version 1.0
 */
@RestController
@RequestMapping("/consultantEvaluation")
public class ConsultantEvaluationController {
    @Autowired
    private ConsultantEvaluationService consultantEvaluationService;
    @PostMapping
    public R insertEvaluation(@RequestBody ConsultantEvaluation consultantEvaluation) {
        int i = consultantEvaluationService.insert(consultantEvaluation);
        if (i>0) {
            return R.ok("添加成功");

        }else {
            return R.fail("添加失败");
        }
    }

    @DeleteMapping("/{id}")
    public R deleteEvaluationById(@PathVariable Integer id) {
        int i = consultantEvaluationService.deleteEvaluationById(id);
        if (i>0) {
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }
    @PutMapping
    public R updateEvaluation(@RequestBody ConsultantEvaluation consultantEvaluation) {
        int i = consultantEvaluationService.updateEvaluation(consultantEvaluation);
        if (i>0) {
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }
    @GetMapping("/{id}")
    public R selectEvaluationById(@PathVariable Integer id) {
        ConsultantEvaluation consultantEvaluation = consultantEvaluationService.selectEvaluationById(id);
        if (consultantEvaluation!=null) {
            return R.ok(consultantEvaluation);
        }else {
            return R.fail("查询失败");
        }
    }
        @GetMapping
    public R selectAll() {
        List<ConsultantEvaluation> consultantEvaluationList = consultantEvaluationService.selectAll();
        if (consultantEvaluationList!=null) {
            return R.ok(consultantEvaluationList);
        }else {
            return R.fail("查询失败");
        }
    }
    @GetMapping("/consultant/{consultantId}")
    public R selectByConsultantId(@PathVariable Integer consultantId) {
        List<ConsultantEvaluation> consultantEvaluationList = consultantEvaluationService.selectByConsultantId(consultantId);
        if (consultantEvaluationList!=null) {
            return R.ok(consultantEvaluationList);
        }else {
            return R.fail("查询失败");
        }
    }

}


